package com.yanqu.road.server.cmd.activity.busyfarming;

import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.activity.BusyFarmingProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.activity.busyfarming.BusyFarmingMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = Protocol.S_BUSY_FARMING_WATERING_FROM_CROSS,desc = "浇水")
public class BusyFarmingWateringCmdFromCross implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {

        BusyFarmingProto.BusyFarmingWateringCrossReqMsg reqMsg = BusyFarmingProto.BusyFarmingWateringCrossReqMsg.parseFrom(packet.getBytes());

       int ret = BusyFarmingMgr.crossWatering(reqMsg.getActivityId(), reqMsg.getLandId(), reqMsg.getUserId(), reqMsg.getSrcServerId(),
                reqMsg.getSrcUserId(), PlayerBasePb.parseToUserBaseInfo(reqMsg.getUserBaseInfo()));

       if(ret != 0){
           BusyFarmingProto.BusyFarmingWateringCrossRespMsg.Builder respMsg = BusyFarmingProto.BusyFarmingWateringCrossRespMsg.newBuilder();
           respMsg.setActivityId(reqMsg.getActivityId());
           respMsg.setRet(ret);
           respMsg.setSrcServerId(reqMsg.getSrcServerId());
           respMsg.setSrcUserId(reqMsg.getUserId());
           GamePlayerMgr.sendPacket(0, YanQuMessageUtils.buildMessage(Protocol.C_BUSY_FARMING_WATERING_BACK, respMsg));
       }
    }
}
